<template>
    <div>
        <van-goods-action>
            <van-goods-action-icon 
            :icon="isCollected?'star':'star-o'" 
            :text="isCollected?'已收藏':'未收藏'" 
            color="red" 
            @click="clickCollet"/>
            <van-goods-action-icon icon="cart-o" text="购物车" :badge="isLogin?goodsCount:0" @click="$router.push('/shopcart')"/>
            <van-goods-action-button type="warning" text="加入购物车" @click="showCart"/>
            <van-goods-action-button type="danger" text="立即购买" />
        </van-goods-action>
    </div>
</template>

<script>
export default {
    data () {
        return {
            isCollected:false,
            isLogin:false
        }
    },
    props:["goodsCount"],
    created(){
        let token = localStorage.getItem("token")
        if(token){
            this.isLogin=true
        }
    },
    methods:{
        showCart(){
            this.$emit("isShowCart")
        },
        clickCollet(){
            // 在用户没有登录的情况下收藏时,给予提示
            // let token = localStorage.getItem("token")
            // if(!token){
            //     this.$toast("请先登录!")
            //     setTimeout(() => {
            //         this.$router.push("/user")
            //     }, 1000);
            //     return
            // }
            let ret=this.utils.mustLogin()
            if(!ret) return
            this.isCollected=!this.isCollected
        }
    }
}
</script>
 
<style lang = "less" scoped>
    .van-goods-action{
      z-index: 9999;
  }
</style>